package com.zqxq.lottery.entity.o2o.order;


import com.zqxq.common.utils.BigDecimalUtils;
import com.zqxq.common.utils.DispatcherUtils;
import com.zqxq.lottery.entity.po.order.UserOrderBetPO;
import com.zqxq.lottery.entity.vo.order.UserOrderBetVO;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description ：
 * @Author ： 解风
 * @Date ： 2018/03/14 16:11
 */
public class UserOrderBetO2O {

    public static UserOrderBetVO toVO(UserOrderBetPO po) {
        if (po == null) {
            return null;
        }
        UserOrderBetVO userOrderBetVO = new UserOrderBetVO();
        userOrderBetVO.setId(DispatcherUtils.parseString(po.getId()));
        userOrderBetVO.setUserId(DispatcherUtils.parseString(po.getUser_id()));
        userOrderBetVO.setOrderId(DispatcherUtils.parseString(po.getOrder_id()));
        userOrderBetVO.setLotteryId(DispatcherUtils.parseString(po.getLottery_id()));
        userOrderBetVO.setPeriod(po.getPeriod());
        userOrderBetVO.setRedNum(po.getRed_num());
        userOrderBetVO.setBlueNum(po.getBlue_num());
        userOrderBetVO.setBetNum(DispatcherUtils.parseString(po.getBet_num()));
        userOrderBetVO.setBetTimes(DispatcherUtils.parseString(po.getBet_times()));
        userOrderBetVO.setPlayType(DispatcherUtils.parseString(po.getPlay_type()));
        BigDecimal prizeDecimal = BigDecimalUtils.getValue(po.getPrize(),2) ;
        String prize = prizeDecimal == null ? null : prizeDecimal.toPlainString();
        userOrderBetVO.setPrize(prize);
        BigDecimal afterTaxDecimal = BigDecimalUtils.getValue(po.getPrize(),2) ;
        String afterTax = afterTaxDecimal == null ? null : afterTaxDecimal.toPlainString();
        userOrderBetVO.setAfterTax(afterTax);
        userOrderBetVO.setStatus(DispatcherUtils.parseString(po.getStatus()));
        userOrderBetVO.setWinInfo(po.getWin_info());
        userOrderBetVO.setCreateTime(DispatcherUtils.parseDateTimeStr(po.getCreate_time()));
        userOrderBetVO.setUpdateTime(DispatcherUtils.parseDateTimeStr(po.getUpdate_time()));
        return userOrderBetVO;
    }

    public static UserOrderBetPO toPO(UserOrderBetVO vo) {
        if (vo == null) {
            return null;
        }
        UserOrderBetPO userOrderBetPO = new UserOrderBetPO();
        userOrderBetPO.setId(DispatcherUtils.parseLong(vo.getId()));
        userOrderBetPO.setUser_id(DispatcherUtils.parseLong(vo.getUserId()));
        userOrderBetPO.setOrder_id(DispatcherUtils.parseLong(vo.getOrderId()));
        userOrderBetPO.setLottery_id(DispatcherUtils.parseLong(vo.getLotteryId()));
        userOrderBetPO.setPeriod(vo.getPeriod());
        userOrderBetPO.setRed_num(vo.getRedNum());
        userOrderBetPO.setBlue_num(vo.getBlueNum());
        userOrderBetPO.setPlay_type(DispatcherUtils.parseInt(vo.getPlayType()));
        userOrderBetPO.setBet_num(DispatcherUtils.parseInteger(vo.getBetNum()));
        userOrderBetPO.setBet_times(DispatcherUtils.parseInteger(vo.getBetTimes()));
        userOrderBetPO.setPrize(BigDecimalUtils.getBigDecimal(vo.getPrize()));
        userOrderBetPO.setAfter_tax(BigDecimalUtils.getBigDecimal(vo.getAfterTax()));
        userOrderBetPO.setStatus(DispatcherUtils.parseInteger(vo.getStatus()));
        userOrderBetPO.setWin_info(vo.getWinInfo());
        userOrderBetPO.setCreate_time(DispatcherUtils.parseDateTime(vo.getCreateTime()));
        userOrderBetPO.setUpdate_time(DispatcherUtils.parseDateTime(vo.getUpdateTime()));
        return userOrderBetPO;
    }

    public static List<UserOrderBetVO> toVOList(List<UserOrderBetPO> list){
        List<UserOrderBetVO> result = new ArrayList();
        if(list != null && list.size() > 0){
            for (UserOrderBetPO po : list) {
                result.add(toVO(po));
            }
        }
        return result;
    }
}
